package com.zx.service.impl;

import com.zx.annotations.Autowired;
import com.zx.annotations.Service;
import com.zx.dao.AccountDao;
import com.zx.pojo.Account;
import com.zx.service.TransferService;

/**
 * @author 应癫
 */
@Service
public class TransferServiceImpl implements TransferService {


    // 最佳状态
    @Autowired
    private AccountDao accountDao;


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            int a= 1/0;
            to.setMoney(to.getMoney()+money);
            if(money == 0){
                throw new RuntimeException("转账数不可等于零");
            }
            accountDao.updateAccountByCardNo(to);
            accountDao.updateAccountByCardNo(from);

    }
}
